﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

using ERPStore.Extensions;

namespace ERPStore.Web.Controllers.ActionFilters
{
	public class ExceptionActionFilter : HandleErrorAttribute
	{
		public override void OnException(ExceptionContext filterContext)
		{
			var logger = GlobalConfiguration.Configuration.DependencyResolver.GetService<ERPStore.Logging.ILogger>();
			if (!filterContext.Exception.Data.Contains("Master"))
			{
				filterContext.Exception.Data.Add("Master", this.Master);
			}
			if (!filterContext.Exception.Data.Contains("Controller"))
			{
				filterContext.Exception.Data.Add("Controller", filterContext.Controller.GetType().FullName);
			}
			if (!filterContext.Exception.Data.Contains("RawUrl"))
			{
				filterContext.Exception.Data.Add("RawUrl", filterContext.HttpContext.Request.RawUrl);
			}
			logger.Error(filterContext.Exception);
			// base.OnException(filterContext);
		}
	}
}
